﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using ZX.SYS.Library;
using ZX.CRM.Bussiness;
using ZX.CRM.Library;
using ZX.DBModule;
using ZX.Common;
using ZX.BLL.Extend;
using ZX.BLL;
using ZX.Mapping;
namespace ZX.WebApp.Crm.Hodometer
{
    public partial class NewInCalendar : EditUIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                bindTime();
                string hid = Request.QueryString["HID"];
                if (hid != null && hid != "")
                {
                    getbyid(hid);
                }
                else
                {
                    this.txtstartdate.Value = Convert.ToDateTime(this.GetStringFromQueryString("DATED", "")).ToString("yyyy-MM-dd");
                    this.txtenddate.Value = this.txtstartdate.Value;
                }
            }
        }
        string strFlag = "", strListProduct = "";
        BCrmDeliverTrain OrderProduct = new BCrmDeliverTrain();
        /// <summary>
        /// 获取字符参数
        /// </summary>
        /// <param name="key"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public string GetStringFromQueryString(string key, string defaultValue)
        {
            string queryStringValue;


            // Attempt to get the value from the query string
            queryStringValue = this.QueryString[key];

            // If we didn't find anything, just return
            //
            if (queryStringValue == null)
                return defaultValue;

            return queryStringValue;

        }
        protected void btnDel_OnClick(object sender, EventArgs e)
        {
            string hid = Request.QueryString["HID"];
            bool bl = false;
            if (hid != null && hid != "")
            {
                CrmInnerTeachHodometer twp = new CrmInnerTeachHodometer();
                twp.ID = new Guid(hid);
                BaseBussnies bwp = new BaseBussnies(twp);
                bwp.delete("OrderId='00000000-0000-0000-0000-000000000000' and BeginDate between'" + txtstartdate.Value + "' and '" + txtenddate.Value + "'");
                bl=bwp.delete();
            }
            Page.ClientScript.RegisterStartupScript(this.GetType(), "AlertResult", "AlertResult('" + bl + "')", true);
        }
        public string PageTitle
        { get { return this.GetStringFromQueryString("title", ""); } }
        public string Flag
        { get { return strFlag; } }

        public string ListCrmProduct
        {
            get
            {
                return strListProduct;
            }
        }
        protected void getbyid(string hid)
        {
            CrmInnerTeachHodometer cth = new CrmInnerTeachHodometer();
            cth.ID = new Guid(hid);
            CrmInnerTeachHodometer twp = new CrmInnerTeachHodometer();
            BaseBussnies bwp = new BaseBussnies(twp);
            IList<CrmInnerTeachHodometer> hd = bwp.GetEntitys<CrmInnerTeachHodometer>("ID='" + hid + "'");
            if (hd != null)
            {
                ddlcolor.SelectedValue = hd[0].backcolor;
                OrderProductID.Value = hd[0].OrderId.ToString();
                txtOrderProductID.Value = hd[0].OrderId.ToString();
                reason.Value = hd[0].Reason;
                txtstartdate.Value = hd[0].BeginDate.ToString("yyyy-MM-dd");

                txtenddate.Value = hd[0].EndDate.ToString("yyyy-MM-dd");
                string fsm = hd[0].BeginDate.Hour < 10 ? "0" + hd[0].BeginDate.Hour.ToString() : hd[0].BeginDate.Hour.ToString();
                string fss = hd[0].BeginDate.Minute < 10 ? "0" + hd[0].BeginDate.Minute.ToString() : hd[0].BeginDate.Minute.ToString();
                string fem = hd[0].EndDate.Hour < 10 ? "0" + hd[0].EndDate.Hour.ToString() : hd[0].EndDate.Hour.ToString();
                string fes = hd[0].EndDate.Minute < 10 ? "0" + hd[0].EndDate.Minute.ToString() : hd[0].EndDate.Minute.ToString();
                ddlStartMin.SelectedValue = fsm;
                ddlStartSec.SelectedValue = fss;
                ddlEndMin.SelectedValue = fem;
                ddlEndSec.SelectedValue = fes;
                //Page.ClientScript.RegisterStartupScript(this.GetType(), "Review", "Reviewform()", true);
            }
        }
        private void bindTime()
        {
            for (int i = 0; i < 24; i++)
            {
                ListItem itemHour = new ListItem();
                itemHour.Text = i < 10 ? "0" + i.ToString() : i.ToString();
                itemHour.Value = i < 10 ? "0" + i.ToString() : i.ToString();
                ddlStartMin.Items.Add(itemHour);
            }
            for (int i = 0; i < 60; i++)
            {
                ListItem itemMinute = new ListItem();
                itemMinute.Text = i < 10 ? "0" + i.ToString() : i.ToString();
                itemMinute.Value = i < 10 ? "0" + i.ToString() : i.ToString();
                ddlStartSec.Items.Add(itemMinute);
            }
            for (int i = 0; i < 24; i++)
            {
                ListItem itemHour = new ListItem();
                itemHour.Text = i < 10 ? "0" + i.ToString() : i.ToString();
                itemHour.Value = i < 10 ? "0" + i.ToString() : i.ToString();
                ddlEndMin.Items.Add(itemHour);
            }
            for (int i = 0; i < 60; i++)
            {
                ListItem itemMinute = new ListItem();
                itemMinute.Text = i < 10 ? "0" + i.ToString() : i.ToString();
                itemMinute.Value = i < 10 ? "0" + i.ToString() : i.ToString();
                ddlEndSec.Items.Add(itemMinute);
            }
        }
        //BTCrmCrustomerOrder order = new BTCrmCrustomerOrder();
        //public string ListRecord
        //{ get { return GetListCrmProduct(); } }
        //private string GetListCrmProduct()
        //{
        //    IList<V_CrmOrderProduct> list = order.GetAllOrderProduct(new Guid(this.ID.Value));
        //    if (list != null && list.Count > 0)
        //    {
        //        return ZX.Common.Globals.ObjectToJSON(list);
        //    }
        //    else
        //    {
        //        return "";
        //    }
        //}

    }
}